home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C++
/
Applications
/
PICSee Dust 1.01
/
Quaternary Source
/
Class_ProgressBar.cpp
< prev
next >
Wrap
Text File
|
1995-11-15
|
4KB
|
158 lines
/*
File: Class_ProgressBar.c++
6/22/94
Version History;
1.1 11/13/95
Changed increment methods; added IncrementBy() & IncrementTo()
*/
#include "Class_ProgressBar.h"
#include "TimerUtils.h"
// ---------------------------------------------------------------------------
ProgressBar::ProgressBar(Rect *theBounds, short max, short cur, GrafPtr owner) {
ownerPort = owner;
bkgndRect = fillRect = frameRect = *theBounds;
InsetRect(&bkgndRect, 1, 1);
InsetRect(&fillRect, 2, 2);
fillRect.right = fillRect.left;
maxVal = max;
curVal = cur;
stepVal = 1;
smoothProgress = true;
useFillColor = useBkgndColor = setupYet = false;
// Set to black
fillColor.red = fillColor.green = fillColor.blue =
bkgndColor.red = bkgndColor.green = bkgndColor.blue = 0;
} // END short ctor
// ---------------------------------------------------------------------------
ProgressBar::ProgressBar(Rect *theBounds, short max, short cur,
GrafPtr owner, RGBColor *fill, RGBColor *bkgnd) {
ownerPort = owner;
bkgndRect = fillRect = frameRect = *theBounds;
InsetRect(&bkgndRect, 1, 1);
InsetRect(&fillRect, 2, 2);
fillRect.right = fillRect.left;
maxVal = max;
curVal = cur;
stepVal = 1;
smoothProgress = true;
setupYet = false;
if (fill != nil) {
useFillColor = true;
fillColor = *fill;
}
else
useFillColor = false;
if (bkgnd != nil) {
useBkgndColor = true;
bkgndColor = *bkgnd;
}
else
useBkgndColor = false;
} // END long ctor
// ---------------------------------------------------------------------------
void ProgressBar::Update() {
Draw();
} // END Update
// ---------------------------------------------------------------------------
void ProgressBar::Increment() {
if (curVal <= maxVal) {
curVal += stepVal;
Draw();
}
} // END Increment
// ---------------------------------------------------------------------------
void ProgressBar::IncrementBy(short stepValue) {
if (curVal <= maxVal) {
curVal += stepValue;
Draw();
}
} // END IncrementBy
// ---------------------------------------------------------------------------
void ProgressBar::IncrementTo(short newCurVal) {
if (curVal <= maxVal) {
curVal = newCurVal;
Draw();
}
} // END IncrementTo
// ---------------------------------------------------------------------------
void ProgressBar::Draw() {
GrafPtr savePort;
PenState savePen;
RGBColor foreSave;
short rightBounds;
//if (curVal > maxVal) return; // We've finished already; exit.
if (curVal > maxVal)
curVal = maxVal;
GetPort(&savePort);
SetPort(ownerPort);
GetPenState(&savePen);
if (useFillColor || useBkgndColor)
GetForeColor(&foreSave);
PenNormal();
if (!setupYet) {
// We've just started, so do some setup...
FrameRect(&frameRect);
if (useBkgndColor) {
RGBForeColor(&bkgndColor);
PaintRect(&bkgndRect);
}
setupYet = true;
}
float rightBoundsAdd = ((float)curVal/maxVal) * float(bkgndRect.right - bkgndRect.left - 2);
rightBounds = fillRect.left + rightBoundsAdd;
if (smoothProgress) {
if (useFillColor)
RGBForeColor(&fillColor);
StartTimerFPS(200);
while (fillRect.right <= rightBounds) {
if (TimerDoNow()) {
FillRect(&fillRect, (ConstPatternParam)&qd.black);
fillRect.right++;
ResetTimer();
}
}
StopTimer();
}
else {
fillRect.right = rightBounds;
if (useFillColor)
RGBForeColor(&fillColor);
PaintRect(&fillRect);
}
SetPenState(&savePen);
if (useFillColor || useBkgndColor)
RGBForeColor(&foreSave);
SetPort(savePort);
} // END Draw